package com.ruoyi.smart.task;

import com.ruoyi.smart.service.DeviceStatusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DeviceStatusCleanupTask {

    private final DeviceStatusService deviceStatusService;

    public DeviceStatusCleanupTask(DeviceStatusService deviceStatusService) {
        this.deviceStatusService = deviceStatusService;
    }

    /**
     * 每天凌晨2点清理过期设备状态（默认过期时间为30天）
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void cleanupExpiredDevices() {
        log.info("开始清理过期设备状态");
        long expiryTime = 30 * 24 * 60 * 60 * 1000L; // 30天
        deviceStatusService.cleanupExpiredDevices(expiryTime);
        log.info("过期设备状态清理完成");
    }
}
